package com.example.learn_spring_boot3.controller;

import com.example.learn_spring_boot3.annotation.PassToken;
import com.example.learn_spring_boot3.service.ExcelService;
import com.example.learn_spring_boot3.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/excel")
public class ExcelController {
    @Autowired
    private ExcelService excelService;

    @PostMapping("/upload")
    public ResponseEntity<ResponseData<Object>> upload(@ModelAttribute("file") MultipartFile file) throws IOException {
        return excelService.upload(file);
    }

    @PassToken
    @GetMapping("/download")
    public void download(@RequestParam("studentIds") String studentIds, HttpServletResponse response) throws IOException {
        excelService.download(studentIds, response);
    }
}
